<template>
	<view class="SOreturn">
		<u-navbar  title="回执" :background="background" title-color="#FFF" back-icon-color="#fff"></u-navbar>
		<view class="SOreturn-weight">
			<text >车牌号</text>
			<view class=" SOreturn-weight-ipt">
				{{detailsList.ORMTB440CA01}}
			</view>
		</view>
		<view class="SOreturn-weight">
			<text >回执物料</text>
			<view class=" SOreturn-weight-ipt">
				{{detailsList.ORMTB440CC02}}
			</view>
		</view>
		<view class="SOreturn-weight">
			<text >回执重量</text>
			<view class=" SOreturn-weight-ipt">
				{{detailsList.oldORMTB440CC04}}
				<text>吨</text>
			</view>
		</view>
		<view class="SOreturn-weight">
			<text >确认重量</text>
			<view class=" SOreturn-weight-ipt">
				<input type="text" v-model="detailsList.ORMTB440CE02" value="" @input="ipt"/>
				<text>吨</text>
			</view>
		</view>
		<view class="SOreturn-weight">
			<text >运费单价</text>
			<view class=" SOreturn-weight-ipt">
				{{detailsList.ORMTB440CA21}}
				<text>元</text>
			</view>
		</view>
		<view class="SOreturn-weight">
			<text >运费金额</text>
			<view class=" SOreturn-weight-ipt">
				{{detailsList.money}}
				<text>元</text>
			</view>
		</view>
		<view class="SOreturn-upImg">
			<text >回执记录</text>
			<view class="SOreturn-upImg-icon" @click="picClick">
				<!-- <image src="" alt=""> -->
				<image :src="detailsList.ORMTB440CE01" />
			</view>
		</view>
		<view class="SOreturn-btn" v-if="detailsList.ORMTB440CF01==4">
			<button type="default" @click="serve">确定</button>
			<button type="default" @click="reTap">取消</button>
		</view>
		<u-toast ref="uToast" />
		<view class="" style="width: 100vw; height: 100vh;">
			<previewImage :saveBtn='false' :rotateBtn='false' ref="previewImage" :imgs="detailsList.imgList"></previewImage>
		</view>
	</view>
</template>

<script>
	import { Decimal } from '../../static/api/decimal.min.js'
	import previewImage  from '@/components/kxj-previewImage/kxj-previewImage.vue'
	export default{
		components: { previewImage},
		data(){
			return {
				background: {
					backgroundColor: '#00a1f1',
				},
				detailsList:'',
				userinfo:JSON.parse(uni.getStorageSync('userinfo')),
			}
		},
		onLoad(option) {
			this.id=option.ORMTB440ID
			this.querOrder()
		},
		methods:{
			picClick() {
				this.$refs.previewImage.open(0);
			},
			reTap(){
				uni.navigateBack({
					delta:1
				})
			},
			ipt(){
				var num=String(this.detailsList.ORMTB440CE02)
				num = num.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
				num = num.replace(/^\./g,"1"); //验证第一个字符是数字
				num = num.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
				num = num.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
				num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
				if(num.indexOf(".")< 0 && num !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
				    num= parseFloat(num)
				}
				num=String(num)
				if(num.indexOf(".")>0){
					var arr=num.split('.')
					if(arr[1].length>1){
						num=Number(num.toString().match(/^\d+(?:\.\d{0,2})?/));
					} 
				}
				var weight=num||0
				this.detailsList.money=new Decimal(weight).mul(new Decimal(this.detailsList.ORMTB440CA21))
				this.$nextTick(function(){
					this.detailsList.ORMTB440CE02=num
				})
			},
			querOrder(){
				uni.showLoading({
				    title: '加载中...',
					mask:true
				});
				this.detailsList=''
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/selectDetails', 
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB440ID: this.id,
					},
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							this.detailsList=res.data.data
							this.detailsList.oldORMTB440CC04=this.detailsList.ORMTB440CE02||0
							if(this.detailsList.ORMTB440CA21){
							}else{
								this.detailsList.ORMTB440CA21=0
							}
							this.detailsList.imgList=[]
							if(this.detailsList.ORMTB440CE01){
								this.detailsList.imgList.push(this.detailsList.ORMTB440CE01)
							}
							this.detailsList.money=new Decimal(this.detailsList.oldORMTB440CC04).mul(new Decimal(this.detailsList.ORMTB440CA21))
						}else{
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon:false
							})
						}
					},
					fail: (res) => {
						console.log(res)
						uni.hideLoading();
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon:false
						})
					}
				});
			},
			serve(){
				uni.showLoading({
				    title: '加载中...',
					mask:true
				}); 
				var ID =''
				if (this.userinfo.sign == 'CUS-2'||this.userinfo.sign == 'CUS-3') {
					ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/updateOrmtbce', 
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB440CE07:this.userinfo.PERTB005ID,
						ORMTB440CE08:this.userinfo.PERTB005CA02,
						ORMTB440CE09:this.detailsList.ORMTB440CE02,
						ORMTB440CE10:this.detailsList.money,
						ORMTB440ID:this.detailsList.ORMTB440ID,
						ORMTB440CA21:this.detailsList.ORMTB440CA21,
						ORMTB410ID:ID,
						Sign:this.userinfo.sign
					},
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							this.$refs.uToast.show({
								title: '回执成功',
								type: 'default',
								icon:false
							})
							uni.navigateBack({
								delta:1
							})
						}else{
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon:false
							})
						}
					},
					fail: (res) => {
						console.log(res)
						uni.hideLoading();
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon:false
						})
					}
				});
			}
		}
	}
</script>

<style scoped>
	.SOreturn-weight{
		display: flex;
		justify-content: space-between;
		padding: 20rpx 0 0;
		margin: 0 30rpx;
		border-bottom: 1px solid #e3e3e3;
	}
	.SOreturn-weight-ipt,.SOreturn-upImg{
		display: flex;
		
	}
	.SOreturn-weight-ipt input{
		height: 60rpx;
		width: 200rpx;
		text-align: right;
		padding-right: 10rpx;
	}
	.SOreturn-weight-ipt text{
		height: 60rpx;
	}
	.SOreturn-upImg{
		padding: 20rpx 20rpx 0;
	}
	.SOreturn-upImg text{
		display: flex;
		align-items: center;
	}
	.SOreturn-upImg-icon{
		height: 200rpx;
		width: 200rpx;
		line-height: 200rpx;
		text-align: center;
		color: #999;
		margin-left: 15rpx;
		border: 1px solid #e3e3e3;
	}
	.SOreturn-upImg-icon image{
		width: 100%;
		height: 100%;
	}
	.SOreturn-btn{
		display: flex;
		padding: 90rpx 20rpx 0;
	}
	.SOreturn-btn button{
		width: 150rpx;
		background-color: #00A1F1;
		color: #FFF;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 30rpx;
	}
	.SOreturn-btn button:last-child{
		background-color: #ffaa00;
	}
</style>
